<?php
use Application\Model\vn3dUtil;
$this->headScript()
    ->prependFile($this->basePath() . '/js/faq_edittor.js')
    ->appendFile($this->basePath() . '/js/tinymce/tinymce.min.js')
    ->appendFile($this->basePath() . '/js/tinymce/jquery.tinymce.min.js');
$action = 'edit';

?>
<script type="text/javascript">
$(document).ready(function(){

	setTinyEdittor();

	$(".vn3d_delte_image").click(function(evt){

		var imageID=$(this).attr("image");
		bootbox.confirm("Bạn có muốn xóa?", function(result) {
			  if(result){

		$.ajax({
	        url: "/admin/product/delete-image",
	        type: "POST",
	        dataType:"json",
	        data: {image:imageID}, //The data your sending to page
	        success: function(data){
            if(data==1){
            	$("#"+imageID).remove();
            }

	        },
	        error:function(){
	            console.log("AJAX request was a failure");
	        }
	      });


			  }

			});
		});

	$("#vn3d_select_category_id li").click(function(){
     var cateogry_id=$(this).attr("category");
     console.log(cateogry_id);
     var cateogry_name=$(this).html();
     $("#vn3d_category_id").html(cateogry_name);
     $("#vn3d_imp_category_id").val(cateogry_id);

		});

	$("#cancel").click(function(){
		bootbox.confirm("Bạn không muốn lưu?", function(result) {
			  if(result){
				  var back_url=$("#vn3d_back").attr("href");
				  location.href=back_url;
			  }
		});

	});

});



</script>
<style>
#price {
	width: 300px;
}

.control-group img {
	height: auto;
	width: 150px;
	overflow: hidden;
}

.vn3d_banner_product img {
	width: 100% !important;
	height: auto;
}
</style>
<ol class="breadcrumb">
	<li><a id="vn3d_back" href="/admin/product/index/<?php echo $groupProductID;?>">Nhóm
			sản phẩm</a></li>
	<li class="active">Sản phẩm</li>
</ol>
<div class="col-sm-14">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">Thêm sản phẩm</h3>
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-14">
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('product', array(
    'action' => "edit",
    "urlseo" => $groupProductID,
    "id" => $productID
)));
$form->setAttribute('class', 'navbar-form');
$form->prepare();
// $form->prepare();
echo $this->form()->openTag($form);
?>
<div class="control-group">
<label group_product="<?php echo $groupProduct->id;?>" id="vn3d_category_id"><?php echo $groupProduct->name;?></label>
						<div class="controls">
						<input style="display: none;" type="text" name="category_id" value="<?php echo $groupProduct->id;?>" id="vn3d_imp_category_id" />
							<div class="btn-group">
								<button type="button" class="btn btn-default dropdown-toggle"
									data-toggle="dropdown">
									Chọn nhóm của sản phẩm <span class="caret"></span>
								</button>
								<ul id="vn3d_select_category_id" class="dropdown-menu" role="menu"
									aria-labelledby="dropdownMenu2">
									<?php
									foreach ($menu as $key => $category) {

									?>
									<?php if($category['parent_id']==null){?>
									<li role="presentation" class="divider"></li>
									<li role="presentation" class="dropdown-header"><?php echo $category['name'];?></li>
									<?php }else{?>
								    <li role="presentation" category="<?php echo $category['id'];?>"><a role="menuitem" tabindex="-1" href="#" category="<?php echo $category['id'];?>"><?php echo $category['name'];?></a></li>
								    <?php
									}
								    }
								    ?>
								</ul>

							</div>
						</div>
	</div>


					<div class="control-group">
						<label>Tên sản phẩm</label>
						<div class="controls">
		<?php
$name = $form->get('name');
$name->setValue($product->name);
echo $this->formRow($name);
?>
	</div>
					</div>
					<div class="control-group">
<label>Tóm tắt</label>
	<div class="controls">
		<?php
		$short_desc=$form->get('short_desc');
		$short_desc->setValue($product->short_desc);
		echo $this->formRow($short_desc);?>
	</div>
</div>
					<div class="control-group">
						<label>Mô tả sản phẩm</label>
						<div class="controls">
		<?php
$desc = $form->get('desc');
$desc->setValue($product->desc);
echo $this->formRow($desc);
?>
	</div>
					</div>
					<div class="control-group">
						<label>Giá</label>
						<div class="controls">
		<?php
$price = $form->get('price');
$price->setValue($product->price);
echo $this->formRow($price);
?><span>&nbsp;&nbsp;$</span>
						</div>
					</div>
					<div class="control-group">
						<label>Mã sản phẩm</label>
						<div class="controls" style="width: 350px;">
		<?php
$code = $form->get('code');
$code->setValue($product->code);
echo $this->formRow($code);
?>
	</div>
					</div>
					<hr>
					<div class="control-group ">
						<label>File bán sản phẩm</label>
						<div class="controls" style="width: 350px;">
		<?php
$product_file = $form->get('product_file');
$product_file->setValue($product->product_file);
echo $this->formRow($product_file);
echo vn3dUtil::getProductFileHtml($product);
?>
	</div>
					</div>
					<hr>
					<div class="control-group">
						<label>Video(link nhúng từ Youtube)</label>
						<div class="controls" style="width: 350px;">
		<?php
$video = $form->get('video');
$video->setValue($product->video);
echo $this->formRow($video);
echo $product->video;
?>
	</div>
					</div>
					<hr>
					<div class="control-group vn3d_banner_product">
						<label>Banner sản phẩm</label>
						<div class="controls" style="width: 100%;">
		<?php
$banner = $form->get('banner');
// $banner->setValue("http://3dbinh.com/banner/31");
echo $this->formRow($banner);
echo vn3dUtil::getBannerProductHtml($product);
?>

	</div>
					</div>
					<hr>
					<div class="control-group">
						<label>Ảnh mô tả sản phẩm</label>
						<div class="controls" style="width: 350px;">
		<?php
echo $this->formRow($form->get('image'));
?>

	</div>
					</div>
					<div class="control-group"
						style="float: left; width: 100%; margin-bottom: 30px;">
						<label></label>
						<div class="controls">
		<?php
foreach ($images as $key => $image) {

    $imageID = $image->id;
    $titleImage = $image->name;
    ?>
        	<div class="col-md-3 full-left" id="<?php echo $imageID;?>">
								<img style="-webkit-user-select: none"
									alt="<?php echo $titleImage;?>"
									title="<?php echo $titleImage;?>"
									src="/image/<?php echo $imageID;?>" /> <input type="button"
									value="Xóa" class="vn3d_delte_image btn btn-xs btn-danger"
									image="<?php echo $imageID;?>" />
							</div>
        	<?php
}
?>


	</div>
					</div>

					<div class="control-group">
						<br>
						<div class="controls">
							<input type="submit" class="btn btn-primary" id="submit"
								value="Lưu thay đổi" /> <input type="button"
								class="btn simplemodal-close" data-dismiss="modal"
								value="Bỏ qua" id="cancel" />
						</div>
					</div>
<?php

echo $this->form()->closeTag();
?>
</div>